﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Plane.Properties;
using Plane;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;

namespace Plane
{
    public partial class GameChoosing : Form
    {
        private MainWindow main;

        private PictureBox[] difficultyOptions;
        private int difficulty = 0;
        private int planeShape = 1;
        private char ps1;
        private char ps2;
        private char ps3;
        private string username;
        //0简单 1中等 2困难
        public GameChoosing(string planeSkinSelect,MainWindow main)
        {
            InitializeComponent();
            difficultyOptions = new PictureBox[] {
                    picEasyClick,
                    picMediClick,
                    picDifcClick};
            SelectDifficulty(0);
            SelectShape(2, planeSkinSelect[2], planeSkinSelect[0], planeSkinSelect[1]);
            ps1 = planeSkinSelect[2];
            ps2 = planeSkinSelect[0];
            ps3 = planeSkinSelect[1];
            //gameform = new GameForm(this,main);
            this.main = main;
            //this.gameform = gameform;
        }
        public GameChoosing(string planeSkinSelect, MainWindow main,string currusername)
        {
            InitializeComponent();
            difficultyOptions = new PictureBox[] {
                    picEasyClick,
                    picMediClick,
                    picDifcClick};
            SelectDifficulty(0);
            SelectShape(2, planeSkinSelect[2], planeSkinSelect[0], planeSkinSelect[1]);
            ps1 = planeSkinSelect[2];
            ps2 = planeSkinSelect[0];
            ps3 = planeSkinSelect[1];
            //gameform = new GameForm(this,main);
            this.main = main;
            //this.gameform = gameform;
            this.username = currusername;
        }
        private void SelectDifficulty(int dif)
        {
            //选中时图片变化
            picEasyClick.Image = (dif == 0) ?
            Properties.Resources.easy2:
            Properties.Resources.easy;

            picMediClick.Image = (dif == 1) ?
                Properties.Resources.medium2:
            Properties.Resources.medium;

            picDifcClick.Image = (dif== 2) ?
                Properties.Resources.hard2:
                Properties.Resources.hard;
            difficulty = dif;
        }
        private void SelectShape(int shape,char ps1,char ps2,char ps3)
        {
            //选中时图片变化
            if (ps1 == '0')
            {
                picPlane1.Image = Resources._lock;
            }
            else
            {
                picPlane1.Image = (shape == 1) ?
                Properties.Resources.plane1L :
                Properties.Resources.plane1;
            }

            picPlane2.Image = (shape == 2) ?
            Properties.Resources.plane2Lpng :
            Properties.Resources.plane2;

            if (ps3 == '0')
            {
                picPlane3.Image = Resources._lock;
            }
            else
            {
                picPlane3.Image = (shape == 3) ?
                Properties.Resources.plane3L :
                Properties.Resources.plane3;
            }
            planeShape = shape;
        }
        //难度选择按钮
        private void picEasyClick_Click(object sender, EventArgs e)
        {
            SelectDifficulty(0);
        }
        private void picMediClick_Click(object sender, EventArgs e)
        {
            SelectDifficulty(1);
        }
        private void picDifcClick_Click(object sender, EventArgs e)
        {
            SelectDifficulty(2);
        }
        private void GameChoosing_Load(object sender, EventArgs e)
        {

        }

        private void buttonComform_Click(object sender, EventArgs e)
        {
            GameSetting.Difficulty = difficulty;
            //this.DialogResult = DialogResult.OK;
            //this.Close();
                            switch (GameSetting.Difficulty)
                            {
                                case 0:
                                    Fighter.FIGHTER_OFFSET = 1;
                                    Fighter.FIGHTER_GENERATE_RATE = 40;
                                    EnemyBullet.BULLET_HURT = 1;
                                    break;
                                case 1:
                                    Fighter.FIGHTER_OFFSET = 3;
                                    Fighter.FIGHTER_GENERATE_RATE = 30;
                                    EnemyBullet.BULLET_HURT = 2;
                                    break;
                                case 2:
                                    Fighter.FIGHTER_OFFSET = 5;
                                    Fighter.FIGHTER_GENERATE_RATE = 20;
                                    EnemyBullet.BULLET_HURT = 3;
                                    break;

                                }
            GameSetting.Shape = planeShape;
            switch (GameSetting.Shape)
            {
                case 1:
                    MyPlane.myPlaneImg = Resources.plane1;
                    MyPlane.myPlaneImgS = Resources.plane1;
                    MyPlane.myPlaneImgL = Resources.plane1T;
                    MyPlane.myPlaneImgR = Resources.plane1T;
                    break;
                case 2:
                    MyPlane.myPlaneImg = Resources.plane2;
                    MyPlane.myPlaneImgS = Resources.plane2;
                    MyPlane.myPlaneImgL = Resources.planeLeft;
                    MyPlane.myPlaneImgR = Resources.planeRight;
                    break;
                case 3:
                    MyPlane.myPlaneImg = Resources.plane3;
                    MyPlane.myPlaneImgS = Resources.plane3;
                    MyPlane.myPlaneImgL = Resources.plane3T;
                    MyPlane.myPlaneImgR = Resources.plane3T;
                    break;

            }
            this.Hide();
            GameForm gameform = new GameForm(this, main, username);
            gameform.Show();
        }

        private void picPlane1_Click(object sender, EventArgs e)
        {
            if (ps1 == '1')
            {
                SelectShape(1, ps1, ps2, ps3);
            }
        }

        private void picPlane2_Click(object sender, EventArgs e)
        {
            SelectShape(2, ps1, ps2, ps3);
        }

        private void picPlane3_Click(object sender, EventArgs e)
        {
            if (ps3 == '1')
            {
                SelectShape(3, ps1, ps2, ps3);
            }
        }

        private void buttonBack_Click(object sender, EventArgs e)
        {
            MainWindow mainWindow=new MainWindow(username);
            mainWindow.Show();
            this.Close();
        }
    }
}
